package com.example.composecamera

import android.net.Uri
import androidx.compose.runtime.Composable
import androidx.navigation.NavHostController
import androidx.navigation.NavType
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.navArgument
import com.example.composecamera.ui.screen.MainScreen
import com.example.composecamera.ui.screen.PhotoScreen
import com.example.composecamera.ui.screen.Screen

@Composable
fun NavGraph(navController: NavHostController) {
    NavHost(
        navController = navController,
        startDestination = Screen.Main.route
    ) {
        composable(route = Screen.Main.route) {
            MainScreen(
                navigateToPhotoScreen = { uri ->
                    navController.navigate("${Screen.Photo.route}/${Uri.encode(uri.toString())}")
                }
            )
        }
        composable(
            route = "${Screen.Photo.route}/{uriString}",
            arguments = listOf(navArgument("uriString") { type = NavType.StringType })
        ) { backStackEntry ->
            val encodeUriString = backStackEntry.arguments?.getString("uriString")
            PhotoScreen(uri = Uri.parse(Uri.decode(encodeUriString)))
        }
    }
}